package com.rms.server.Dao;

import com.rms.server.Domain.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface DishMapper {
    @Insert("INSERT INTO Dish (dish_name, category, dexcription, price) " +
            "VALUES (#{dishName}, #{category}, #{dexcription}, #{price})")
    @Options(useGeneratedKeys = true, keyProperty = "dishId")
    int insertDish(Dish dish);

    @Delete("DELETE FROM Dish WHERE dish_id = #{dishId}")
    int deleteDish(Long dishId);

    @Update("UPDATE Dish SET dish_name = #{dishName}, category = #{category}, " +
            "dexcription = #{dexcription}, price = #{price} WHERE dish_id = #{dishId}")
    int updateDish(Dish dish);

    @Select("SELECT dish_id AS dishId, dish_name AS dishName, category, dexcription, price FROM Dish WHERE dish_id = #{dishId}")
    Dish selectDishById(Long dishId);


    @Select("SELECT dish_id AS dishId, dish_name AS dishName, category, dexcription, price FROM Dish")
    List<Dish> selectAllDishes();
    // 随机查询8个菜品
    @Select("SELECT dish_id AS dishId, dish_name AS dishName, category, dexcription, price FROM Dish ORDER BY RAND() LIMIT 8")
    List<Dish> getRandomDishes();
}
